public class Solution50 {
    public double myPow(double x, int n) {
        if (n==0){
            return 1;
        }
        boolean flag=true;
        long nn;
        if (n<0){
            nn=-(long)n;
            flag=false;
        }else{
            nn=n;
        }
        double ans=x;
        int end=0;
        for (int i=32;i>=0;i--){
            if ((nn&(1L<<i))>0){
                end=i;
                break;
            }
        }
        for (int i=end-1;i>=0;i--){
            ans=ans*ans;
            if ((nn&(1L<<i))>0){
                ans=ans*x;
            }
        }
        if (!flag){
            ans=1/ans;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution50().myPow(2,-2));
    }
}
